
#include <BFont>
#include <BPainter>
#include <BProgressBar>
#include "member_BProgressBar.h"

using namespace BWE;

#define member					(*(member_BProgressBar*)_ptr)
#define member_allocate()		_ptr = new member_BProgressBar(this)
#define member_release()		delete (member_BProgressBar*)_ptr

BProgressBar::BProgressBar(BWidget* parent) : BWidget(parent)
{
	member_allocate();
}
BProgressBar::BProgressBar(Orientation orientation, BWidget* parent) : BWidget(parent)
{
	member_allocate();
	member.orientation = orientation;
}
BProgressBar::~BProgressBar()
{
	member_release();
}

void BProgressBar::setOrientation(Orientation orientation)
{
	if (member.orientation != orientation)
	{
		member.orientation = orientation;
		this->fresh();
	}
}
Orientation BProgressBar::orientation() const
{
	return member.orientation;
}

void BProgressBar::setValue(int value)
{
	value = bLimit(value, member.minimum, member.maximum);
	if (member.value != value)
	{
		member.value = value;
		this->fresh();
	}
}
int BProgressBar::value() const
{
	return member.value;
}

void BProgressBar::setMinimum(int minimum)
{
	if (member.minimum != minimum)
	{
		member.minimum = minimum;
	}
}
int BProgressBar::minimum() const
{
	return member.minimum;
}

void BProgressBar::setMaximum(int maximum)
{
	member.maximum = maximum;
}
int BProgressBar::maximum() const
{
	return member.maximum;
}

void BProgressBar::freshEvent(const BEvent& event)
{
	member.freshRects();
}
void BProgressBar::paintEvent(const BEvent& event)
{
	BWidget::paintEvent(event);

	BPainter painter(this);

	painter.setColor(Color_Indicator);
	painter.fillRect(member.rect);

	painter.setColor(Color_Text);
	painter.drawText(member.textRect, member.text);
}
